import {
  createRouter,
  createWebHistory,
  createWebHashHistory,
} from "vue-router";

const routes = [
  {
    path: "/",
    component: () => import("@/views/Home/index.vue"),
    children: [
      {
        path: "/",
        name: "home",
        meta: {
          title: "Home",
        },
        component: () => import("@/views/Home/home/index.vue"),
      },
      {
        path: "/market",
        meta: {
          title: "Market",
        },
        component: () => import("@/views/Home/market/index.vue"),
      },
      {
        path: "/self",
        meta: {
          title: "Self",
        },
        component: () => import("@/views/Home/self/index.vue"),
      },
      {
        path: "/news",
        meta: {
          title: "News",
        },
        component: () => import("@/views/Home/news/index.vue"),
      },
      {
        path: "/mine",
        meta: {
          title: "Mine",
        },
        component: () => import("@/views/Home/mine/index.vue"),
      },
    ],
  },
  {
    path: "/login",
    name: "login",
    component: () => import("@/views/Login/index.vue"),
    meta: {
      title: "Login",
    },
  },
  {
    path: "/register",
    name: "register",
    component: () => import("@/views/Register/index.vue"),
    meta: {
      title: "Register",
    },
  },
  {
    path: "/check",
    name: "check",
    component: () => import("@/views/Check/index.vue"),
    meta: {
      title: "Check",
    },
  },
  {
    path: "/financial",
    name: "financial",
    meta: {
      title: "Financial",
    },
    component: () => import("@/views/Home/home/financial/index.vue"),
  },
  {
    path: "/financialList",
    name: "financialList",
    meta: {
      title: "financial.order.list",
    },
    component: () => import("@/views/Home/home/financialList/index.vue"),
  },
  {
    path: "/detail",
    meta: {
      title: "Detail",
    },
    component: () => import("@/views/Home/market/detail/index.vue"),
    props: (route) => {
      const { pairsName, id } = route.query;
      return {
        pairsName,
        id,
      };
    },
  },
  {
    path: "/test",
    meta: {
      title: "Test",
    },
    component: () => import("@/views/Home/market/Test/index.vue"),
  },
  {
    path: "/charge",
    name: "charge",
    component: () => import("@/views/Home/mine/charge/index.vue"),
    meta: {
      title: "home.Mine.deposit",
    },
  },
  {
    path: "/pocket",
    name: "pocket",
    component: () => import("@/views/Home/mine/pocket/index.vue"),
    meta: {
      title: "home.Mine.deposit",
    },
  },
  {
    path: "/withdraw",
    name: "withdraw",
    component: () => import("@/views/Home/mine/withdraw/index.vue"),
    meta: {
      title: "home.Mine.withdraw",
    },
  },
  {
    path: "/history",
    name: "history",
    component: () => import("@/views/Home/mine/history/index.vue"),
    meta: {
      title: "home.Mine.history",
    },
  },
  {
    path: "/authentication",
    name: "authentication",
    component: () => import("@/views/Home/mine/authentication/index.vue"),
    meta: {
      title: "home.Mine.authentication",
    },
  },
  {
    path: "/loan",
    name: "loan",
    component: () => import("@/views/Home/mine/loan/index.vue"),
    meta: {
      title: "home.Mine.loan",
    },
  },
  {
    path: "/waitLoan",
    name: "waitLoan",
    component: () => import("@/views/Home/mine/waitLoan/index.vue"),
    meta: {
      title: "waitLoan.waitLoan",
    },
  },
  {
    path: "/waitLoanIng",
    name: "waitLoanIng",
    component: () => import("@/views/Home/mine/waitLoanIng/index.vue"),
    meta: {
      title: "waitLoan.shenqing",
    },
  },
  {
    path: "/myLoan",
    name: "myLoan",
    component: () => import("@/views/Home/mine/myLoan/index.vue"),
    meta: {
      title: "home.Mine.loan",
    },
  },
  {
    path: "/help",
    name: "help",
    component: () => import("@/views/Home/mine/help/index.vue"),
    meta: {
      title: "home.Mine.help",
    },
  },
  {
    path: "/customer",
    name: "customer",
    component: () => import("@/views/Home/mine/customer/index.vue"),
    meta: {
      title: "home.Mine.customer",
    },
  },
  {
    path: "/card",
    name: "card",
    component: () => import("@/views/Home/mine/card/index.vue"),
    meta: {
      title: "home.Mine.card",
    },
  },
  // 将匹配所有内容并将其放在 `$route.params.pathMatch` 下
  {
    path: "/:pathMatch(.*)*",
    name: "NotFound",
    component: () => import("@/views/NotFound/index.vue"),
    meta: {
      title: "NotFound",
    },
  },
];

const mode = import.meta.env.VITE_APP_TITLE;
const option = {
  history: createWebHistory(),
  routes,
};

if (mode == "pro-android") {
  option.history = createWebHashHistory();
} else if (mode == "pro-ios") {
  option.history = createWebHistory();
} else {
  option.history = createWebHistory();
}
export const router = createRouter({
  ...option,
});

export default (app) => app.use(router);
